package com.meilingcloud.web.controller.tool;

import com.meilingcloud.common.annotation.Log;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.core.page.TableDataInfo;
import com.meilingcloud.common.enums.BusinessType;
import com.meilingcloud.common.utils.SecurityUtils;
import com.meilingcloud.system.domain.SysLabelType;
import com.meilingcloud.system.service.ISysLabelTypeService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 标签类型 Controller
 *
 * @author chenl
 * @date 2021-04-14
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/tool/labelType")
public class SysLabelTypeController extends BaseController {

    private final ISysLabelTypeService iSysLabelTypeService;

    /**
     * 查询标签类型 列表
     */
    @PreAuthorize("@ss.hasPermi('tool:labelType:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysLabelType sysLabelType) {
        startPage();
        List<SysLabelType> list = iSysLabelTypeService.queryList(sysLabelType);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('tool:labelType:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        return AjaxResult.success(iSysLabelTypeService.list());
    }

    /**
     * 获取标签类型 详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:labelType:query')")
    @GetMapping(value = "/{labelTypeId}")
    public AjaxResult getInfo(@PathVariable("labelTypeId") Long labelTypeId) {
        return AjaxResult.success(iSysLabelTypeService.getLabelType(labelTypeId));
    }

    /**
     * 新增标签类型
     */
    @PreAuthorize("@ss.hasPermi('tool:labelType:add')")
    @Log(title = "标签类型 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLabelType sysLabelType) {
        sysLabelType.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iSysLabelTypeService.save(sysLabelType));
    }

    /**
     * 修改标签类型
     */
    @PreAuthorize("@ss.hasPermi('tool:labelType:edit')")
    @Log(title = "标签类型 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLabelType sysLabelType) {
        sysLabelType.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iSysLabelTypeService.updateLabelType(sysLabelType));
    }

    /**
     * 删除标签类型
     */
    @PreAuthorize("@ss.hasPermi('tool:labelType:remove')")
    @Log(title = "标签类型 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{labelTypeIds}")
    public AjaxResult remove(@PathVariable Long[] labelTypeIds) {
        return toAjax(iSysLabelTypeService.removeLabelTypes(Arrays.asList(labelTypeIds)));
    }
}
